﻿#pragma once

#include <QVariant>
#include <QObject>
#include <QDebug>
#include <QMutexLocker>
#include <QVariantMap>
#include "ubNotification.h"
#pragma execution_character_set("utf-8")

// class ConfigVar------------------------------------------------
class ConfigVar : public QObject
{
	Q_OBJECT

public:
	explicit ConfigVar(QObject* parent = nullptr);
	~ConfigVar();

	Q_INVOKABLE  void setValue(const QString& key, const QVariant& value);

	Q_INVOKABLE QVariant getValue(const QString& key);

	Q_INVOKABLE void dispalyAllValues();
private:
	QMutex m_mutex; // 互斥锁

};

// class Jslog------------------------------------------------------------
class Jslog : public QObject
{
	Q_OBJECT
public:
	explicit  Jslog(QObject* parent = nullptr);
	~Jslog();
	Q_INVOKABLE void debug(QString message);
	Q_INVOKABLE void info(QString message);
	Q_INVOKABLE void warn(QString message);
	Q_INVOKABLE void error(QString message);

private:
		QMutex m_mutex; // 互斥锁
};

// class GlobalData----------------------------------------------	
class GlobalData : public QObject
{
    Q_OBJECT
public:
	explicit  GlobalData(QObject* parent = nullptr);
	~GlobalData();

    Q_INVOKABLE void setValue(const QString& key, const QVariant& value);

	Q_INVOKABLE QVariant getValue(const QString& key);


private:
	QMutex m_mutex; // 互斥锁
    QMap<QString, QVariant> data; // 用于存储字段和值
};

// class JsNotification----------------------------------------------	
class JsNotification : public QObject
{
	Q_OBJECT
public:
	explicit  JsNotification(QObject* parent = nullptr);
	~JsNotification();

	Q_INVOKABLE void Send(QString name, QVariantMap userInfo);

private:
	QMutex m_mutex; // 互斥锁
};


class SaveCSVPath : public QObject
{
	Q_OBJECT
public:
	explicit  SaveCSVPath(QObject* parent = nullptr);
	~SaveCSVPath();

	/// <summary>
	/// 保存csv文件
	/// </summary>
	/// <param name="Path">文件路径</param>
	/// <param name="Result">文件内容QMap（测试项 - 值）</param>
	/// <param name="csvName">文件名 后缀会自己加日期</param>
	/// <returns></returns>
	/// 20230425.csv
	Q_INVOKABLE	bool saveCSV(QString Path, QVariantMap Result, QString key);

private:
	QMutex m_mutex; // 互斥锁
};


class SaveQimagePath : public QObject
{
	Q_OBJECT
public:
	explicit  SaveQimagePath(QObject* parent = nullptr);
	~SaveQimagePath();

	/// <summary>
	/// 保存图片
	/// </summary>
	/// <param name="Path">文件路径</param>
	/// <param name="image">图片</param>
	/// <param name="imageName">文件名 后缀会自己加日期</param>
	/// <returns></returns>
	/// 20230425.png
	Q_INVOKABLE	bool saveTo(const QString Path ,const QImage &image);

private:
	QMutex m_mutex; // 互斥锁
};